package com.leaf.lowcode.utils;

import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class TokenQuery {
    public String query() {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        HttpMethod method = HttpMethod.POST;
        // 以表单的方式提交
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        //添加参数developerId
        MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
        multiValueMap.add("developerId", "qw4a65023da7604ebaac9830432dd75c07");
        multiValueMap.add("developerKey", "ODdkNTM5N2UtODgzNi00MjUyLTg3MmItYzhkYjcyN2RjMjIy");
        //封装
        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(multiValueMap, headers);
        //post请求
        ResponseEntity<String> responseEntity = restTemplate.exchange("https://workuat.spic.com.cn/mgr/portal/token/getToken.do", method, requestEntity, String.class);
        //提交
        String body = responseEntity.getBody();
        return body;
    }
}
